﻿using Api.Application.Command.Deion;
using Api.DTO;
using Domain;
using ErrorCode;
using Infrastructure;
using MediatR;

namespace Api.Application.Handler.Deion
{
    public class GetDeionHandler : IRequestHandler<GetDeionCommand, ApiPaging<DeionDTO>>
    {
        private readonly IBase<DeionModel> deionRepo;

        public GetDeionHandler(IBase<DeionModel> deionRepo)
        {
            this.deionRepo = deionRepo;
        }   
        public Task<ApiPaging<DeionDTO>> Handle(GetDeionCommand request, CancellationToken cancellationToken)
        {
            ApiPaging<DeionDTO> paging=new ApiPaging<DeionDTO>();
            var deion = deionRepo.GetAll();
            var linq = from a in deion
                       select new DeionDTO()
                       {
                           DeionId = a.DeionId,
                           DeionName = a.DeionName,
                       };
            paging.Code = ApiEnum.OK;
            paging.Data = linq.ToList();
            paging.Msg = "部门查询成功";
            return Task.FromResult(paging);
        }
    }
}
